/*--------------------------------------------------------------------------------------*\
**
** dialog_marketplace.h
**
** Heroes IV
** Copyright 2000, The 3DO Company
**
\*--------------------------------------------------------------------------------------*/

#ifndef DIALOG_MARKETPLACE_H_INCLUDED
#define DIALOG_MARKETPLACE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>
#include "bitmap_group_ptr.h"
#include "game_window.h"
#include "material_icons.h"

class   t_adventure_frame;
class   t_button;
class   t_player;
class   t_scrollbar;
class   t_text_window;

class t_dialog_marketplace : public t_window
{
public:
	t_dialog_marketplace ( t_window* parent );
    void init_dialog( t_window *parent, t_adventure_frame* frame, std::string const& name_text, std::string const& intro_text, 
                int market_efficiency_ratio );

protected:
	t_bitmap_group_ptr		    m_bitmaps_ptr;
	t_button *                  m_buy_button;
    int                         m_cost_numerator;
    int                         m_cost_denominator;

    // Market ratio is always 1:m_market_ratio_efficiency
    int                         m_market_efficiency_ratio;

    t_button *                  m_market_button[k_material_count];
	t_text_window *             m_market_exchange_text[k_material_count];
	t_window *                  m_market_frame;
	std::vector<t_screen_point> m_market_frame_locations;
    int                         m_market_item_index;
	t_window *                  m_market_item_window;
	bool                        m_market_selected;
    int                         m_market_quantity;
	t_text_window *             m_market_quantity_text;

    int                         m_max_scroll_value;
    t_button *                  m_max_button;
    
    t_button *                  m_player_button[k_material_count];
	t_text_window *             m_player_amount_text[k_material_count];
	t_window *                  m_player_frame;
	std::vector<t_screen_point> m_player_frame_locations;
    int                         m_player_item_index;
	t_window *                  m_player_item_window;
	bool                        m_player_selected;
    int                         m_player_quantity;
	t_text_window *             m_player_quantity_text;
    
	t_player *                  m_player_ptr;
	int						    m_player_funds;
	t_scrollbar *               m_scrollbar;

    void buy_clicked( t_button* button );
	bool can_buy();
    void close_click( t_button* button );
    void player_material_clicked( t_button* button, int index );
    void market_material_clicked( t_button* button, int index );
    void max_clicked( t_button* button );
    void reset_market_rate_text();
    void scrollbar_move( t_scrollbar* scrollbar, int value );
    void show_exchange_items ();
    void show_exchange_rates ();
    void show_player_material_amount ();
};


inline bool t_dialog_marketplace::can_buy()
{
	return m_player_selected && m_market_selected && (m_player_item_index != m_market_item_index);
}

#endif // DIALOG_MARKETPLACE_H_INCLUDED
